package com.jn.erp.wechat.staff.api.controller;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.jn.erp.common.core.page.TableDataInfo;
import com.jn.erp.common.core.result.AjaxResult;
import com.jn.erp.security.controller.BaseWebAuthController;
import com.jn.erp.web.api.common.entity.InteractMessage;
import com.jn.erp.web.api.student.entity.TRenewalAlertsConfig;
import com.jn.erp.web.api.student.entity.dto.StudentRenewalDto;
import com.jn.erp.web.api.student.service.RenewalAlertsConfigService;
import com.jn.erp.web.api.student.service.StudentService;
import com.jn.erp.wechat.common.api.controller.base.BaseWxAuthController;
import com.jn.erp.wechat.common.api.entity.dto.WxUserDto;
import com.jn.erp.wechat.core.WxTableDataInfo;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;

@RestController
@RequestMapping("/wx/alerts")
public class MpRenewalAlertsController extends BaseWxAuthController {

    @Autowired
   private StudentService studentService;

    @Autowired
   private RenewalAlertsConfigService renewalAlertsConfigService;

    /**
     * 预警列表    /renewalAlerts/alertsList
     */
    @GetMapping("/alertsList")
    public WxTableDataInfo auditionList(StudentRenewalDto studentRenewalDto) {
        WxUserDto wxUser=getWxUser();
        startPage();
        studentRenewalDto.setOrgId(wxUser.getOrgIdLong());
        List<StudentRenewalDto> list = studentService.alertsList(studentRenewalDto);
        return getWxDataTable(list);
    }

    /**
     * 预警设置   /renewalAlerts/alertSettings
     */
    @PostMapping("/alertSettings")
    public AjaxResult alertSettings(@RequestBody StudentRenewalDto studentRenewalDto) {
        WxUserDto wxUser=getWxUser();
        studentRenewalDto.setOrgId(wxUser.getOrgIdLong());
        renewalAlertsConfigService.alertSettings(studentRenewalDto);
        return success("设置成功");
    }

    /**
     * 预警设置列表   /renewalAlerts/settingsList
     */
    @PostMapping("/settingsList")
    public AjaxResult settingsList(TRenewalAlertsConfig tRenewalAlertsConfig) {
        WxUserDto wxUser=getWxUser();
        tRenewalAlertsConfig.setOrgId(wxUser.getOrgIdLong());
        TRenewalAlertsConfig setting =  renewalAlertsConfigService.settingsList(tRenewalAlertsConfig);
        return success(setting);
    }




    @Autowired
    private com.jn.erp.web.api.common.service.InteractMessageService interactMessageService;

    /**
     * 续费提醒      /interactMessage/renewalReminders
     */
    @PostMapping("/renewalReminders")
    public AjaxResult renewalReminders(@RequestBody InteractMessage interactMessage) {
        WxUserDto wxUser=getWxUser();
        interactMessage.setOrgId(wxUser.getOrgIdLong());
        interactMessage.setCreator(wxUser.getUserId());
        Long aLong = interactMessageService.renewalReminders(interactMessage);
        return success("成功");
    }

}
